﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Collections;


namespace System
{
    public interface IBaseDal : IDal, IEBaseDal
    {
        #region 属性

        /// <summary>
        /// 对象所在程序集名
        /// </summary>
        string ModelAssemblyName { get; set; }
        
        /// <summary>
        /// 对象名
        /// </summary>
        string ModelName { get; set; }
        
        /// <summary>
        /// 对象所在表名
        /// </summary>
        string TableName { get; set; }
        
        /// <summary>
        /// 对象类型
        /// </summary>
        Type ModelType { get; }
        
        /// <summary>
        /// 对象
        /// </summary>
        BaseModel BaseModel { get; }
        
        /// <summary>
        /// 对象主键名
        /// </summary>
        string PrimaryKey { get; set; }

        #endregion     

        #region DAL 

        #region 基本方法

        /// <summary>
        /// 判断是否存在符合条件的记录
        /// </summary>
        /// <param name="filter">筛选条件</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回结果</returns>
        bool Exists(string filter, List<DBParameter> parameters);
        
        /// <summary>
        /// 获取符合条件的记录数
        /// </summary>
        /// <param name="filter">筛选条件</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回结果</returns>
        int GetCount(string filter, List<DBParameter> parameters);

        /// <summary>
        /// 判断是否存在符合条件的记录
        /// </summary>
        /// <param name="parameters">参数集合</param>
        /// <param name="filter">筛选条件</param>
        /// <returns>返回结果</returns>
        bool Exists(List<DbParameter> parameters, string filter);
        
        /// <summary>
        /// 获取符合条件的记录数
        /// </summary>
        /// <param name="parameters">参数集合</param>
        /// <param name="filter">筛选条件</param>
        /// <returns>返回结果</returns>
        int GetCount(List<DbParameter> parameters, string filter);

        #endregion


        #region 删除

        /// <summary>
        /// 删除符合条件的记录
        /// </summary>
        /// <param name="filter">筛选条件</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回受影响的记录数</returns>
        int Delete(string filter, List<DBParameter> parameters);       
        
        /// <summary>
        /// 删除符合条件的记录
        /// </summary>
        /// <param name="primaryKeyInfo"></param>
        /// <returns>返回受影响的记录数</returns>
        int Delete(DBParameter primaryKeyInfo);
        
        /// <summary>
        /// 删除符合条件的记录
        /// </summary>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回受影响的记录数</returns>
        int Delete(List<DBParameter> parameters);
       
        /// <summary>
        /// 删除符合条件的记录
        /// </summary>
        /// <param name="parameters">参数集合</param>
        /// <param name="filter">筛选条件</param>
        /// <returns>返回受影响的记录数</returns>
        int Delete(List<DbParameter> parameters, string filter);
        
        /// <summary>
        /// 删除符合条件的记录
        /// </summary>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回受影响的记录数</returns>
        int Delete(List<DbParameter> parameters);


        #endregion

        #region 更新

        /// <summary>
        /// 更新符合条件的记录中指定字段
        /// </summary>
        /// <param name="fieldName">字段名</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="value">值</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回受影响的记录数</returns>
        int Update(string fieldName, string filter, object value, List<DBParameter> parameters);      
        
        /// <summary>
        /// 更新符合条件的记录中指定字段
        /// </summary>
        /// <param name="parameters">参数集合</param>
        /// <param name="fieldName">字段名</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="value">值</param>
        /// <returns>返回受影响的记录数</returns>
        int Update(List<DbParameter> parameters, string fieldName, string filter, object value);
     
        #endregion

        #region GetTable
  
        /// <summary>
        /// 返回符合条件的记录到DataTable
        /// </summary>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="sorts">排序字段及其方式</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回结果</returns>
        DataTable GetDataTable(string fields, string filter, string sorts, List<DBParameter> parameters);
        
        /// <summary>
        /// 以分页形式返回符合条件的记录到DataTable
        /// </summary>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="recordCount">总记录数。为-1时，将从数据库获取该值</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="sorts">排序字段及其方式</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回结果</returns>
        DataTable GetDataTable(int? pageIndex, int? pageSize, ref int? recordCount, string fields, string filter, string sorts, List<DBParameter> parameters);

  
        /// <summary>
        /// 返回符合条件的记录到DataTable
        /// </summary>
        /// <param name="parameters">参数集合</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="sorts">排序字段及其方式</param>
        /// <returns>返回结果</returns>
        DataTable GetDataTable(List<DbParameter> parameters, string fields, string filter, string sorts);
        
        /// <summary>
        /// 以分页形式返回符合条件的记录到DataTable
        /// </summary>
        /// <param name="parameters">参数集合</param>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="recordCount">总记录数。为-1时，将从数据库获取该值</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="sorts">排序字段及其方式</param>
        /// <returns>返回结果</returns>
        DataTable GetDataTable(List<DbParameter> parameters, int? pageIndex, int? pageSize, ref int? recordCount, string fields, string filter, string sorts);

        #endregion      
     

        #endregion 

        #region GetObject

        /// <summary>
        /// 获取符合条件的对象
        /// </summary>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="sorts">排序字段及其方式</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回对象</returns>
        BaseModel GetObject(string fields, string filter, string sorts, List<DBParameter> parameters);
        
        /// <summary>
        /// 获取符合条件的对象
        /// </summary>
        /// <param name="id">对象ID</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <returns>返回对象</returns>
        BaseModel GetObject(string id, string fields);
        /// <summary>
        /// 获取符合条件的对象
        /// </summary>
        /// <param name="id">对象ID</param>    
        /// <returns>返回对象</returns>
        BaseModel GetObject(string id);
        /// <summary>
        /// 获取符合条件的对象
        /// </summary>
        /// <param name="parameters">参数集合</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <returns>返回对象</returns>
        BaseModel GetObject(List<DBParameter> parameters, string fields);
        
        /// <summary>
        /// 获取符合条件的对象
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回对象</returns>
        BaseModel GetObject(string sql, List<DBParameter> parameters);
        
        /// <summary>
        /// 获取符合条件的对象
        /// </summary>
        /// <param name="dr">IDataReader</param>
        /// <returns>返回对象</returns>
        BaseModel GetObject(IDataReader dr);
        
        /// <summary>
        /// 获取符合条件的对象
        /// </summary>
        /// <param name="dr">DataRow</param>
        /// <returns>返回对象</returns>
        BaseModel GetObject(DataRow dr);
        
        /// <summary>
        /// 获取符合条件的对象
        /// </summary>
        /// <param name="drv">DataRowView</param>
        /// <returns>返回对象</returns>
        BaseModel GetObject(DataRowView drv);

        #endregion

        #region GetObjectList

        /// <summary>
        /// 获取全部对象
        /// </summary>
        /// <returns>返回结果</returns>
        ArrayList GetObjectList();
        
        /// <summary>
        /// 通过IDataReader返回对象集合
        /// </summary>
        /// <param name="dr">IDataReader</param>
        /// <returns>返回结果</returns>
        ArrayList GetObjectList(IDataReader dr);
        
        /// <summary>
        /// 通过DataTable返回对象集合
        /// </summary>
        /// <param name="dt">DataTable</param>
        /// <returns>返回结果</returns>
        ArrayList GetObjectList(DataTable dt);
       
        /// <summary>
        /// 通过DataView返回对象集合
        /// </summary>
        /// <param name="dv">DataView</param>
        /// <returns>返回结果</returns>
        ArrayList GetObjectList(DataView dv);
        
        /// <summary>
        /// 执行SQL语句，返回对象集合
        /// </summary>
        /// <param name="sql">SQL语句</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回结果</returns>
        ArrayList GetObjectList(string sql, List<DBParameter> parameters);
        
        /// <summary>
        /// 获取符合条件的对象集合
        /// </summary>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="sorts">排序字段及其方式</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回结果</returns>
        ArrayList GetObjectList(string fields, string filter, string sorts, List<DBParameter> parameters);

        /// <summary>
        /// 以分页形式获取符合条件的对象集合
        /// </summary>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="recordCount">总记录数。为-1时，将从数据库获取该值</param>
        /// <param name="fields">列集合;以","分割,""、null或"*"表示所有列</param>
        /// <param name="filter">筛选条件</param>
        /// <param name="sorts">排序字段及其方式</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回结果</returns>
        ArrayList GetObjectList(int? pageIndex, int? pageSize, ref int? recordCount, string fields, string filter, string sorts, List<DBParameter> parameters);
        

        #endregion

        /// <summary>
        /// 获取符合条件的对象
        /// </summary>
        /// <param name="sqlInfo">封装的筛选信息</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回结果</returns>
        BaseModel GetObject(SqlInfo sqlInfo, List<DBParameter> parameters);

        /// <summary>
        /// 获取符合条件的对象集合
        /// </summary>
        /// <param name="sqlInfo">封装的筛选信息</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回结果</returns>
        ArrayList GetObjectList(SqlInfo sqlInfo, List<DBParameter> parameters);

        /// <summary>
        /// 以分页形式获取符合条件的对象集合
        /// </summary>
        /// <param name="pageInfo">封装的分页数据筛选信息</param>
        /// <param name="parameters">参数集合</param>
        /// <returns>返回结果</returns>
        ArrayList GetObjectList(PageInfo pageInfo, List<DBParameter> parameters);

        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="id">对象ID</param>
        /// <returns>返回受影响的记录数</returns>
        int Delete(string id);
    }
}
